﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpBolt.Tweening;
using SharpBolt.Graphics.GraphicSources;
using InductBase;

namespace SharpBolt.Graphics.Particles
{
    public class ParticleScheme
    {
        public string Name { get; set; }
        
        public List<ParticleStateNode> Nodes { get; set; }

        public int MaxParticlesNumber { get; set; }
        public SpriteSource SpriteSource { get; set; }

        public double Density { get; set; }
        public double PerSecond { get; set; }

        public long LifeTime { get; set; }
        public int RandLifeTime { get; set; }

        public double SpriteAnimationScale { get; set; }
        public double SpriteAnimationSpeed { get; set; }

        public bool OutOfCenter { get; set; }
        public double SpreadAngle { get; set; }
        public double RandSpreadAngle { get; set; }

        public ParticleScheme()
        {
            Name = "Noname";
            Nodes = new List<ParticleStateNode>();
            MaxParticlesNumber = 40000;
            SpriteSource = null;
            LifeTime = 2000;
            RandLifeTime = 100;
            SpriteAnimationScale = 1;
            SpriteAnimationSpeed = 0;

            SpreadAngle = -90;
            RandSpreadAngle = 0;

            Density = 0;
            PerSecond = 2;
        }

        public override string ToString()
        {
            return Name;
        }

        /*
        public string ToFullString()
        {
            string result = "";
            result += "Name\t" + Name + "\n";
            result += "EasingMethod\t" + Easing.EasingDictionary.FirstOrDefault(p=>p.Value == EasingMethod).Key + "\n";
            result += "MaxParticlesNumber\t" + MaxParticlesNumber + "\n";
            result += "SpriteSource\t" + SpriteSource.Name + "\n";
            result += "LifeTime\t" + LifeTime + "\n";
            result += "RandLifeTime\t" + RandLifeTime + "\n";
            result += "AnimationScale\t" + AnimationScale + "\n";
            result += "AnimationSpeed\t" + AnimationSpeed + "\n";
            result += "SpreadAngle\t" + SpreadAngle + "\n";
            result += "RandSpreadAngle\t" + RandSpreadAngle + "\n";
            result += "Nodes\t" + Nodes.Count + "\n";

            for (int i = 0; i < Nodes.Count; i++)
			{
			    result += "Node\t" + i + "\n";
                result += "DColor\t" + Nodes[i].DColor.ToColor().ToString() + "\n";
                result += "Speed\t" + Nodes[i].Speed + "\n";
                result += "Transformation\t" + Nodes[i].Transformation + "\n";
                result += "NodeEnd\t" + i + "\n";
			}                
           
            return result;
        }
         

        static public  ParticleScheme Parse(string input)
        {
            var lines = input.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            ParticleScheme scheme = new ParticleScheme();
            ParticleStateNode node = new ParticleStateNode();

            foreach (var line in lines)
            {
                var args = line.Trim().Split(new[]{'\t'}, StringSplitOptions.RemoveEmptyEntries);

                if (args[0] == "Name") scheme.Name = args[1];

                if (args[0] == "EasingMethod")
                    if (Easing.EasingDictionary.ContainsKey(args[1])) 
                            scheme.EasingMethod = Easing.EasingDictionary[args[1]];

                if (args[0] == "SpriteSource")
                    scheme.SpriteSource = SpriteSource.LoadSprite(args[1].Trim());

                //if (args[0] == "MaxParticlesNumber") scheme.MaxParticlesNumber = Int32.Parse(args[1]);
                if (args[0] == "LifeTime") scheme.LifeTime = long.Parse(args[1]);
                if (args[0] == "RandLifeTime") scheme.RandLifeTime = Int32.Parse(args[1]);
                if (args[0] == "AnimationScale") scheme.AnimationScale = double.Parse(args[1]);
                if (args[0] == "AnimationSpeed") scheme.AnimationSpeed = double.Parse(args[1]);
                if (args[0] == "SpreadAngle") scheme.SpreadAngle = double.Parse(args[1]);
                if (args[0] == "RandSpreadAngle") scheme.RandSpreadAngle = double.Parse(args[1]);

                if (args[0] == "Node")
                {                    
                    node = new ParticleStateNode();
                }

                if (args[0] == "NodeEnd")
                {
                   scheme.Nodes.Add(node);
                }

                if (args[0] == "DColor") node.DColor = Color.Parse(args[1]).ToDColor();
                if (args[0] == "Speed") node.Speed = double.Parse(args[1]);
                if (args[0] == "Transformation") node.Transformation = Transformation.Parse(args[1]);
            }

            return scheme;
        }
         */
    }
}
